<template>
  <div class="home">
    <div class="home-top">
      <!-- <Nav-bar></Nav-bar> -->
    </div>

    <div class="home-one">
       <router-view></router-view>
      <div class="home-left">
        <div class="home-two" v-for="item in tableData" :key="item.id">
          <img :src="item.titleImage" alt="" @click="goToDetail(item.id)" style="cursor: pointer;"  />
          <h2>{{ item.title }}</h2>
          <p>{{ item.description }}</p>
          <el-button type="success" size="mini">{{ item.id }}</el-button>
        </div>
        <div class="fenye">
          <el-pagination background layout="prev, pager, next" :total="this.total" :current-page="current"  @current-change="handleCurrentChange">
        </el-pagination>
        </div>
        
      </div>

      <div class="home-right">
        <div class="home-right-one">
            <img  :src="tableData4.avatar" alt="">
            <h1>{{tableData4.author}}</h1>
            <span>{{tableData4.introduction}}</span>
        </div>
        <div class="home-right-two">
          <h3>分类</h3>
          <div class="home-right-two-one" v-for="item in tableData1" :key="item.id"  @click="goToCategory(item.id,item.name)" style="cursor: pointer;">
            <img src="./img/微信图片_20251018104745_83_3.png" alt="">
            {{item.name}}</div>
        </div>
        <div class="home-right-three">
          <div class="home-right-three-two">
             <h3>标签</h3>
          </div>
          
          <div class="home-right-three-one" v-for="item in tableData3" :key="item.id"  @click="goToTag(item.id, item.name)"
  style="cursor: pointer;">
            
            {{item.name}}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import NavBar from "@/components/NavBar.vue";

export default {
  // components: {
  //   NavBar,
  // },
  data() {
    return {
      tableData: [],
      tableData1: [],
      tableData3: [],
      tableData4: [],
      current:1, //当前页数
      total:0,  //总条数
        
    };
  },
  created() {
    this.getList();
    this.getList2();
    this.getList3();
    this.getList4();
  },
  methods: {
     goToTag(tagId, name) {
    this.$router.push(`/labels?id=${tagId}`);
    localStorage.setItem("tagName", name);
  },
     goToCategory(categoryId,name) {

    
    this.$router.push(`/classify?id=${categoryId}`);
    localStorage.setItem("name",name)
   
    
  },
     goToDetail(id) {
    this.$router.push(`/detail?id=${id}`);
  },
    getList() {
      this.$axios
        .post(`/api/api/index/article/list`, {
          current: this.current,
          size: 10,
        })
        .then((res) => {
          this.tableData = res.data.data;
          console.log(this.tableData, "1111");
          console.log(res);
          this.total=res.data.total
          console.log(this.current);
          
          
          

        })
        .catch((err) => {
          console.log(err);
        });
    },
     getList2() {
      this.$axios
        .post(`/api/api/category/list`)
        .then((res) => {
          this.tableData1 = res.data.data;
          console.log(this.tableData1, "222222");
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
     handleCurrentChange(val) {
    this.current = val;  // 更新当前页码
    this.getList();      // 重新获取对应页的数据
  },
    getList3() {
      this.$axios
        .post(`/api/api/tag/list`)
        .then((res) => {
          this.tableData3 = res.data.data;
          console.log(this.tableData3, "33333");
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
      getList4() {
      this.$axios
        .post(`/api/api/blog/setting/detail`)
        .then((res) => {
          this.tableData4 = res.data.data;
          console.log(this.tableData4, "图片");
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style scoped>
.home {
  background-color: #f4f4f4;
  /* background-color: rgb(63 131 248 / .5); */
}
.home-one {
  width: 100%;

  /* background-color: antiquewhite; */
  margin-top: 20px;
  display: flex;
  justify-content: space-around;
  /* margin-top: 80px; */
}
.home-top {
  width: 100vw;
  position: fixed;
  top: 0;
}
.home-left {
  width: 980px;

  /* background-color: aqua; */
  display: flex;
  /* justify-content: space-around; */
  flex-wrap: wrap;
  margin-left: 200px;

}
.home-two{
  margin: 20px;
}
.home-right {
  width: 300px;
  margin-top: 20px;

 
}
.home-two {
  width: 441px;
  height: 344px;
  background-color: white;
  margin-top: 20px;
  text-align: left;
}
.home-two img {
  width: 441px;
  height: 200px;
}
.home-right-one{
  width: 283px;
  height: 185px;
  background-color: white;
  text-align: center;
  
}
.home-right-one h1{
  margin: 0;
}
.home-right-one img{
  width: 60px;
  height: 60px;
  border-radius: 50%;
  margin-top: 20px;
}
.home-right-two{
  width: 283px;
 
  background-color: white;
  margin-top: 20px;
  text-align: left;

}
.home-right-two h3{
  padding: 5px 10px;
}
.home-right-two-one{
  width: 209px;
  height: 20px;
  padding: 8px 16px;
  display: flex;
  border-radius: 10px;
  margin-left: 30px;

}
.home-right-two-one img{
  width: 16px;
  height: 16px;
  margin-right: 10px;
}
.home-right-two-one:hover{
  background-color: rgb(243 244 246);
  color: rgb(26 86 219);
}
.home-right-three{
  width: 283px;
  background-color: white;
  margin-top: 20px;
  text-align: left;
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;

}
.home-right-three-one{
  margin: 0px 8px 4px 0;
  padding: 2px 10px;
  background-color: rgb(222 247 236);
  font-size: 12px;
  border-radius: 10px;
}
.home-right-three-two{
  width: 300px;
}
.home-right-three-two h3{
  padding: 0 20px;
}
.home-right-three-one:hover{
  background-color: rgb(188 240 218);
}
.fenye{
  width: 100%;
  display: flex;
  justify-content: center;
}
</style>